#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../../../../core/shader_binding_ID.h"
#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"
#include "../../../../core/shader_taster_transform.h"
#include "../../../../core/shader_taster_line.h"

#include "../../../../core/shader_curve.h" 


layout(location = 0) in vec3 inPoint;
layout(location = 1) in vec3 in_L_CPoint;
layout(location = 2) in vec3 in_R_CPoint;
layout(location = 3) in uvec3 in_ID_Type_Color;


layout(location=0) out vec4 vColor;
layout(location=1) out S_CurvePoint3D v_CPoint;
layout(location=5) out vec3 vCameraPos;
layout(location=6) out uint vType;
layout(location=7) out mat4 vMatrix;



void main(void) {
	uint InstanceOffset = gl_InstanceIndex + drawProp.MatrixOffset;
	//uint InstanceOffset = gl_InstanceIndex;

	S_MeshTranformProp prop = m_LinesProp[drawProp.MeshPropOffset + gl_DrawID];
	mat4 mat = mat_Model[InstanceOffset];
	
	if(prop.m_Color > 0){
		vColor = f_glsl_buildColor(prop.m_Color);
	} 
	else {
		vColor = f_glsl_buildColor(in_ID_Type_Color.z) * prop.m_Intensity;
	}

	vMatrix = mat_ProjecView[0];

	v_CPoint.value = (mat * vec4(inPoint, 1)).xyz;
	v_CPoint.L_point = (mat * vec4(in_L_CPoint, 1)).xyz;
	v_CPoint.R_point = (mat * vec4(in_R_CPoint, 1)).xyz;

	//vCameraPos = normalize(inverse(mat3(mat_ProjecView[1])) * vec3(0.0, 0.0, DEF_ForwardDir));
	vCameraPos = (inverse(mat_ProjecView[3]) * vec4(0, 0, 0, 1)).xyz;
	v_CPoint.ID_Type_Color.y = in_ID_Type_Color.y;
}


